package com.wings4.accounting

import com.wings4.security.User

class AccountType {

    String accountTypeName;
    String description;
    Date createDate;
    User createdBy;

    static mapping = {
        createDate(sqlType: 'date');

    }
    static constraints = {
        description(nullable: true);
    }
    public static void initialize(){
//        println("session.user is:"+session.getValue('user'));

        def insertQuery = [
                ["Credit","Credit Account",new Date(),User.get(1)] ,
                ["Debit","Debit Account",new Date(),User.get(1)]
        ]
        insertQuery.each {
                AccountType accountType = null;
                try{
                    accountType = new AccountType(accountTypeName: it[0], description: it[1], createDate: it[2], createdBy: it[3]);
                    accountType.save(flush:true);
                } catch(Exception e){
                   e.printStackTrace();
                }

            }
//        if(AccountType.list()==null){
//            String accountTypeName = "Credit";
//            String description = "Credit Account";
//            Date createDate = new Date();
//            User createdBy = User.get(1);
//
//            AccountType accountType = new AccountType();
//            accountType.accountTypeName = accountTypeName;
//            accountType.description = description;
//            accountType.createDate = createDate;
//            accountType.createdBy = createdBy;
//            accountType.save();
//            String accountTypeName1 = "Debit";
//            String description1 = "Debit Account";
//            Date createDate1 = new Date();
//            User createdBy1 = User.get(1);
//            AccountType accountType1 = new AccountType();
//            accountType1.accountTypeName = accountTypeName1;
//            accountType1.description = description1;
//            accountType1.createDate = createDate1;
//            accountType1.createdBy = createdBy1;
//            accountType1.save();
//        }

    }
}
